home *** CD-ROM | disk | FTP | other *** search
/ CD/PC Actual 76 / DVD Actual 1 Marzo 2003.iso / Trial / TurboCAD 7.1 Pro / Data.Cab / F29015_SmObj.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-10  |  7.6 KB  |  339 lines

  1. /******************************************************************/
  2. /*                                                                */
  3. /*                      TurboCAD for Windows                      */
  4. /*                   Copyright (c) 1993 - 1999                    */
  5. /*             International Microcomputer Software, Inc.         */
  6. /*                            (IMSI)                              */
  7. /*                      All rights reserved.                      */
  8. /*                                                                */
  9. /******************************************************************/
  10. // Tool.cpp : Implementation of CDCMTool
  11. #include "stdafx.h"
  12. #include "InsSmObj.h"
  13. #include "SmObj.h"
  14. #include "SdiDialog.h"
  15.  
  16. #include <afxwin.h>
  17.  
  18. const IID IID_Tool = {0x6A48112C,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  19. const IID IID_IApplication = {0x6A481101,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  20.  
  21. /////////////////////////////////////////////////////////////////////////////
  22.  
  23. STDMETHODIMP CInsSmObj::InterfaceSupportsErrorInfo(REFIID riid)
  24. {
  25.     static const IID* arr[] = 
  26.     {
  27.         &IID_ITurboCADTool,
  28.     };
  29.     for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
  30.     {
  31.         if (InlineIsEqualGUID(*arr[i],riid))
  32.             return S_OK;
  33.     }
  34.     return S_FALSE;
  35. }
  36.  
  37.     /* ITurboCADTool properties: */
  38. STDMETHODIMP CInsSmObj::get_ClassID(BSTR* retval)
  39. {
  40.     HRESULT hRes = E_FAIL;
  41.     LPOLESTR olestr = NULL;
  42.  
  43.     try
  44.     {
  45.         *retval = NULL;
  46.  
  47.         hRes = ::StringFromCLSID(CLSID_InsSmObj, &olestr);
  48.         CHECK_HRESULT(hRes)
  49.  
  50.         *retval = ::SysAllocString(olestr);
  51.  
  52.         hRes = S_OK;
  53.     }
  54.     catch (...)
  55.     {
  56.         TRACE_EXCEPTION("CInsSmObj::get_ClassID")
  57.     }
  58.  
  59.     if (olestr != NULL)
  60.         CoTaskMemFree(olestr);
  61.  
  62.     return hRes;
  63. }
  64.  
  65. STDMETHODIMP CInsSmObj::get_Description( BSTR* retval)
  66. {
  67.  
  68.     HRESULT hRes = E_FAIL;
  69.     CString strResult;
  70.     *retval = NULL;
  71.  
  72.     try
  73.     {
  74.         if (strResult.LoadString(IDS_DESCRIPTION))
  75.         
  76.             hRes = S_OK;
  77.             *retval = strResult.AllocSysString();
  78.         
  79.     }
  80.     catch (...)
  81.     {
  82.         TRACE_EXCEPTION("CInsSmObj::get_Description")
  83.     }
  84.  
  85.     return hRes;
  86.  
  87. }
  88.  
  89. /* ITurboCADTool methods: */
  90. STDMETHODIMP CInsSmObj::GetToolInfo(VARIANT FAR* CommandNames,
  91.                                    VARIANT FAR* MenuCaptions,
  92.                                    VARIANT FAR* StatusPrompts,
  93.                                    VARIANT FAR* ToolTips,
  94.                                    VARIANT FAR* Enabled,
  95.                                    VARIANT FAR* WantsUpdates,
  96.                                    long FAR* retval)
  97. {
  98.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  99.  
  100.     
  101.     HRESULT hRes = E_FAIL;
  102.     
  103.     SAFEARRAYBOUND bound = {NUM_TOOLS, 0};
  104.  
  105.     CString cstrText;
  106.     CString cstrTextTemp;
  107.  
  108.     BSTR bstrCommandName = NULL;
  109.     BSTR bstrMenuCaption = NULL;
  110.     BSTR bstrStatusPrompt = NULL;
  111.     BSTR bstrToolTip = NULL;
  112.     BOOL bEnabled = TRUE;
  113.     BOOL bWantsUpdates = TRUE;
  114.  
  115.     
  116.     long lIndicies = 0;
  117.     try
  118.     {
  119.         
  120.         hRes = SafeArrayRedim(CommandNames->parray, &bound);
  121.         CHECK_HRESULT(hRes)
  122.  
  123.         hRes = SafeArrayRedim(MenuCaptions->parray, &bound);
  124.         CHECK_HRESULT(hRes)
  125.  
  126.         hRes = SafeArrayRedim(StatusPrompts->parray, &bound);
  127.         CHECK_HRESULT(hRes)
  128.  
  129.         hRes = SafeArrayRedim(ToolTips->parray, &bound);
  130.         CHECK_HRESULT(hRes)
  131.  
  132.         hRes = SafeArrayRedim(Enabled->parray, &bound);
  133.         CHECK_HRESULT(hRes)
  134.  
  135.         hRes = SafeArrayRedim(WantsUpdates->parray, &bound);
  136.         CHECK_HRESULT(hRes)
  137.  
  138.         //CString cstrText="SDK|Smart Object"; //# Localizable string#
  139.         cstrText.LoadString (IDS_MAINMENU);
  140.         cstrText.Insert(cstrText.GetLength (), '|');
  141.         cstrTextTemp.LoadString (IDS_SUBMENU);
  142.         cstrText.Insert(cstrText.GetLength (), cstrTextTemp);
  143.         cstrText.Insert(cstrText.GetLength (), '|');
  144.         cstrTextTemp.LoadString (IDS_MENUCAPTION);
  145.         cstrText.Insert(cstrText.GetLength (), cstrTextTemp);
  146.         cstrTextTemp.Empty ();
  147.  
  148.         bstrCommandName = cstrText.AllocSysString();
  149.         hRes = SafeArrayPutElement(CommandNames->parray, &lIndicies, (void *)bstrCommandName);
  150.         CHECK_HRESULT(hRes)
  151.  
  152.         cstrText.Empty ();
  153.         cstrText.LoadString (IDS_MENUCAPTION); 
  154.         bstrMenuCaption = cstrText.AllocSysString();
  155.         hRes = SafeArrayPutElement(MenuCaptions->parray, &lIndicies, (void *)bstrMenuCaption);
  156.         CHECK_HRESULT(hRes)
  157.  
  158.           cstrText.LoadString (IDS_PROMT);
  159.         bstrStatusPrompt = cstrText.AllocSysString();
  160.         hRes = SafeArrayPutElement(StatusPrompts->parray, &lIndicies, (void *)bstrStatusPrompt);
  161.         CHECK_HRESULT(hRes)
  162.  
  163.         cstrText.LoadString (IDS_TOOLTIPS);
  164.         bstrToolTip = cstrText.AllocSysString();
  165.         hRes = SafeArrayPutElement(ToolTips->parray, &lIndicies, (void *)bstrToolTip);
  166.         CHECK_HRESULT(hRes)
  167.  
  168.         hRes = SafeArrayPutElement(Enabled->parray, &lIndicies, (void *)&bEnabled);
  169.         CHECK_HRESULT(hRes)
  170.  
  171.         hRes = SafeArrayPutElement(WantsUpdates->parray, &lIndicies, (void *)&bWantsUpdates);
  172.         CHECK_HRESULT(hRes)
  173.  
  174.         *retval = NUM_TOOLS;
  175.     }
  176.     catch (...)
  177.     {
  178.         if (SUCCEEDED(hRes))
  179.             hRes = E_FAIL;
  180.         TRACE_EXCEPTION("CInsSmObj::GetToolInfo")
  181.     }
  182.     return hRes;
  183. }
  184.  
  185. STDMETHODIMP CInsSmObj::CopyBitmap( VARIANT_BOOL LargeButtons, VARIANT_BOOL Monochrome, VARIANT_BOOL FAR* retval)
  186. {
  187.     HRESULT hRes = E_FAIL;
  188.     try
  189.     {
  190.         CHECK_HRESULT(hRes)
  191.         hRes = S_OK;
  192.     }
  193.     catch (...)
  194.     {
  195.         TRACE_EXCEPTION("CInsSmObj::CopyBitmap")
  196.     }
  197.     return hRes;
  198. }
  199.  
  200. STDMETHODIMP CInsSmObj::GetPicture( VARIANT_BOOL LargeButtons, VARIANT_BOOL Monochrome, IDispatch** retval)
  201. {
  202.     HRESULT hRes = E_FAIL;
  203.     try
  204.     {
  205.         CHECK_HRESULT(hRes)
  206.         hRes = S_OK;
  207.     }
  208.     catch (...)
  209.     {
  210.         TRACE_EXCEPTION("CInsSmObj::GetPicture")
  211.     }
  212.     return hRes;
  213. }
  214.  
  215. STDMETHODIMP CInsSmObj::Run( IDispatch* ThisTool, VARIANT_BOOL FAR* retval)
  216. {
  217.     CWnd *pMainWnd = AfxGetMainWnd();
  218.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  219.  
  220.  
  221.     CInsSmObjApp *pApp = (CInsSmObjApp *)AfxGetApp();
  222.  
  223.     HRESULT hRes = E_FAIL;
  224.  
  225.     Tool *pTool = NULL;
  226.     IApplication *pIApp = NULL;
  227.  
  228.  
  229.     RegenMethods *pRegMets=NULL;
  230.     RegenMethod *pIRegMet=NULL;
  231.  
  232.     COleVariant varAperture(0.2);
  233.     COleVariant varItem;
  234.     long lItem = 0;
  235.     long lIndex = 0;
  236.  
  237.     COleVariant varOptional(varMissing);
  238.     COleVariant varType((const long)imsiPolyline);
  239.     
  240.     VARIANT_BOOL    varCopy = FALSE;
  241.     VARIANT_BOOL    varRetval = FALSE;
  242.  
  243.     long lID = 0;
  244.  
  245.     BSTR bstrType = NULL;
  246.     CString    strType;
  247.  
  248.     BSTR bstrDescription=NULL;
  249.     CString strDescription;
  250.  
  251.     BSTR bstrName=NULL;
  252.     CString strName;
  253.  
  254.     HCURSOR hOC = ::SetCursor(::LoadCursor(NULL,IDC_WAIT));
  255.  
  256.  
  257.     try
  258.     {
  259.         hRes = ThisTool->QueryInterface(IID_Tool, (void **)&pTool);
  260.         CHECK_HRESULT(hRes)
  261.  
  262.         hRes = pTool->get_Application(&pIApp);
  263.         CHECK_HRESULT(hRes)
  264.  
  265.          hRes = pIApp->get_RegenMethods(&pRegMets);
  266.         CHECK_HRESULT(hRes)
  267.  
  268.         CSdiDialog *pdlg = new CSdiDialog(this, pMainWnd, pRegMets);
  269.  
  270.         pdlg->Create(CSdiDialog::IDD, NULL /*pMainWnd*/);
  271.  
  272.         VARIANT_BOOL    varRetval1 = FALSE;
  273.         
  274. //        hRes = UpdateToolStatus(ThisTool, FALSE, FALSE, &varRetval1);    
  275.         hRes = UpdateToolStatus(ThisTool, &varRetval1, &varRetval1, &varRetval1);    
  276.         CHECK_HRESULT(hRes)
  277.  
  278.         
  279.         
  280.  
  281.         hRes = S_OK;
  282.     }
  283.     catch (...)
  284.     {
  285.         TRACE_EXCEPTION("CInsSmObj::Run")
  286.     }
  287.     ::SetCursor(hOC);
  288.  
  289.     if(pRegMets != NULL)
  290.     {
  291.         pRegMets->Release();    
  292.         pTool = NULL;
  293.     }
  294.  
  295.     RELEASE(pIApp)
  296.     RELEASE(pTool)
  297.  
  298.     return hRes;
  299. }
  300.  
  301. STDMETHODIMP CInsSmObj::UpdateToolStatus(IDispatch* ThisTool, VARIANT_BOOL FAR* Enabled, VARIANT_BOOL FAR* Checked, VARIANT_BOOL FAR* retval)
  302. {
  303.     HRESULT hRes = E_FAIL;
  304.  
  305.     try
  306.     {
  307.         if(m_bRunned == TRUE) 
  308.         {
  309.             *Enabled = FALSE;
  310.         }
  311.         *retval = TRUE;
  312.         hRes = S_OK;
  313.  
  314.     }
  315.     catch (...)
  316.     {
  317.         TRACE_EXCEPTION("CInsSmObj::UpdateToolStatus")
  318.     }
  319.  
  320.     return hRes;
  321. }
  322.  
  323. STDMETHODIMP CInsSmObj::Initialize( IDispatch * ThisTool, VARIANT_BOOL FAR* retval)
  324. {
  325.     HRESULT hRes = E_FAIL;
  326.  
  327.     try
  328.     {
  329.         *retval = TRUE;
  330.         hRes = S_OK;
  331.  
  332.     }
  333.     catch (...)
  334.     {
  335.         TRACE_EXCEPTION("CInsSmObj::Initialize")
  336.     }
  337.     return hRes;
  338. }
  339.